<?php

/**
 * UserProfile form.
 *
 * @package    jo-tend
 * @subpackage form
 * @author     Ameen SHoman
 * @version    SVN: $Id: sfPropelFormTemplate.php 10377 2008-07-21 07:10:32Z dwhittle $
 */
class registerForm extends sfGuardUserForm
{
    public function configure(){
        $edit_mode = $this->getOption('edit_mode' , false);


        parent::configure();
        if(sfConfig::get('app_sfCMSPlugin_registation_capatcha',true)){
            $this->widgetSchema['capatch'] = new sfWidgetFormMyCaptcha();
            $this->validatorSchema['capatch'] = new sfValidatorMyCaptcha();
        }

        if($edit_mode){
            unset($this['capatch']);
            unset($this['email']);
            unset($this['password']);
            unset($this['password_again']);
        }

    }

    public function doSave($con = null){
        //DEEEEEEEEMO
        $is_new = $this->isNew();

        parent::doSave($con);
        if($is_new){
            $guard_user = $this->getObject();

            $guard_user->setIsActive(0);
            $link_profile_atcivation = new ProfileActiviation();
            $link_profile_atcivation->setsfGuardUser($guard_user);

            $key = md5(rand().time());


            $link_profile_atcivation->setKey($key);
            $link_profile_atcivation->save();
            //$guard_user->getProfile()->setMd5Key( md5( time() + rand() ) );
            //$guard_user->save();
            //$body = nahoMail::getBody('partial', 'cms_profile/mails/user_activiation' , array('guard_user'=>$guard_user));

            $body = get_partial('cms_profile/mails/user_activiation' , array('guard_user'=>$guard_user,'key'=>$key));
            sfContext::getInstance()->getMailer()->composeAndSend( CMS_globals::get_admin_attr('admin_mail'), $guard_user->getProfile()->getEmail(), __('Regsiteration') , $body );
        }


    }
    public function getJavaScripts(){
        return array('all'=>'/sfCMSPlugin/js/register_form.js');
    }
    public function getStylesheets(){
        return array('all'=>'/sfCMSPlugin/css/register_form.css');
    }
}
